package com.movitech.mobile.cz.base.sys.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.modules.vo.PageRequestVO;
import com.movitech.mobile.cz.base.sys.bizvo.BannerRequestVO;
import com.movitech.mobile.cz.base.sys.entity.SBanner;
import com.movitech.mobile.cz.base.sys.service.SBannerService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
 * <p>
 * SBanner 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-02-28
 */
@RestController
@RequestMapping("/v1/sBanner")
@Api(value = "banner维护基础操作接口", description = "banner维护基础操作接口")
public class SBannerController {
    @Autowired
    @Qualifier("sBannerService")
    private SBannerService sBannerService;

    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有banner维护接口",
            notes = "获取所有banner维护接口",
            response = SBanner.class
    )
    public RestReturnResult list() {
        RestReturnResult restReturnResult = RestReturnResult.success();
        Page<SBanner> page = sBannerService.selectPage(new Page<SBanner>());
        restReturnResult.setData(page);
        return restReturnResult;
    }

//    @PostMapping("/searchList/{pageNumber}")
//    @ApiOperation(
//            value = "banner维护列表查询接口",
//            notes = "banner维护列表查询接口",
//            response = SBanner.class
//    )
//    public RestReturnResult searchList(@RequestBody SBanner sBanner,
//                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
//        RestReturnResult restReturnResult = RestReturnResult.success();
//        Page<SBanner> page = new Page<>();
//        page.setCurrent(pageNumber);
//        EntityWrapper wrapper = new EntityWrapper<>();
//        wrapper.setEntity(sBanner);
//        page = sBannerService.selectPage(page,wrapper);
//        restReturnResult.setData(page);
//        return restReturnResult;
//    }

    @GetMapping("/getSBanner/{id}")
    @ApiOperation(
            value = "banner维护对象ID获取接口",
            notes = "banner维护对对象ID获取接口",
            response = SBanner.class
    )
    public RestReturnResult addSBanner(@PathVariable String id) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        SBanner sBanner = sBannerService.selectById(id);
        restReturnResult.setData(sBanner);
        return restReturnResult;
    }

//    @PostMapping("/add")
//    @ApiOperation(
//            value = "banner维护添加接口",
//            notes = "banner维护添加接口",
//            response = SBanner.class
//    )
//    public RestReturnResult add(@RequestBody SBanner sBanner) {
//        RestReturnResult restReturnResult = RestReturnResult.success();
//        sBannerService.insert(sBanner);
//        restReturnResult.setData(sBanner);
//        return restReturnResult;
//    }
//
//    @PutMapping("/update")
//    @ApiOperation(
//            value = "banner维护更新接口",
//            notes = "banner维护更新接口",
//            response = SBanner.class
//    )
//    public RestReturnResult update(@RequestBody SBanner sBanner) {
//        RestReturnResult restReturnResult = RestReturnResult.success();
//        sBannerService.updateById(sBanner);
//        restReturnResult.setData(sBanner);
//        return restReturnResult;
//    }
//
//    @DeleteMapping("/delete/{id}")
//    @ApiOperation(
//            value = "banner维护通过ID删除接口",
//            notes = "banner维护通过ID删除接口",
//            response = SBanner.class
//    )
//    public RestReturnResult update(@PathVariable String id) {
//        RestReturnResult restReturnResult = RestReturnResult.success();
//        sBannerService.deleteById(id);
//        return restReturnResult;
//    }
    
    /**
	 * 外网banner列表接口
	 * @param pageRequestVO
	 * @return
	 */
    @ApiOperation(
          value = "外网banner列表接口",
          notes = "外网banner列表接口",
          response = SBanner.class
    )
	@RequestMapping(value = "/getBannerList", method = RequestMethod.POST)
	@ResponseBody
	public RestReturnResult<Object> getBannerList(@RequestBody PageRequestVO pageRequestVO){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
		
		hResult = sBannerService.getBannerList(pageRequestVO);
		
		return hResult;
		
	}

	/**
	 * banner新增/修改 接口
	 * @param bannerRequestVO
	 * @return
	 */
    @ApiOperation(
            value = "banner新增/修改 接口",
            notes = "banner新增/修改 接口",
            response = SBanner.class
      )
	@RequestMapping(value = "/saveOrUpdateBanner", method = RequestMethod.POST)
	@ResponseBody
	public RestReturnResult<Object> saveOrUpdateBanner(@RequestBody BannerRequestVO bannerRequestVO){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
		
		try{
			hResult = sBannerService.saveOrUpdateBanner(bannerRequestVO);
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}
		
		return hResult;
	}
	
	/**
	 * banner删除接口
	 * @param id
	 * @return
	 */
    @ApiOperation(
            value = "banner删除接口",
            notes = "banner删除接口",
            response = SBanner.class
      )
	@RequestMapping(value = "/deleteBanner", method = RequestMethod.GET)
	@ResponseBody
	public RestReturnResult<Object> deleteBanner(String id){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
		
		try{
			hResult = sBannerService.updateBannerForDel(id);
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}
		
		return hResult;
	}
	
	/**
	 * banner 启用/停用  接口
	 * @param bannerRequestVO
	 * @return
	 */
    @ApiOperation(
            value = "banner 启用/停用  接口",
            notes = "banner 启用/停用  接口",
            response = SBanner.class
      )
	@RequestMapping(value = "/updateBannerStatus", method = RequestMethod.POST)
	@ResponseBody
	public RestReturnResult<Object> updateBannerStatus(@RequestBody BannerRequestVO bannerRequestVO){
		RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
		
		try{
			hResult = sBannerService.updateBannerStatus(bannerRequestVO);
		}catch(Exception e){
			e.printStackTrace();
			hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
		}
		
		return hResult;
	}


}

